import { GTabBar } from "./GTabBar";
import { UICompomentPool } from "../utils/UICompomentPool";
import { GLoadedButton } from "./GLoadedButton";
import { MuiEvent } from "../events/MuiEvent";
import { Button } from "../../../fl/controls/Button";
//class GImageButtonTabBar
    
    export  class GImageButtonTabBar extends GTabBar
    {
        constructor()
        {
            
            super();buttonWidth = 66;
            buttonHeight = 65;
            return;
        }

        protected /* override */ updateDisplayList(): void
        {
            var loc1=null;
            var loc2=null;
            if (_dataProviderChange) 
            {
                reset();
                var loc3=0;
                var loc4=dataProvider;
                for(loc1 of loc4) 
                {
                    loc2 = UICompomentPool.getUICompoment(GLoadedButton);
                    loc2.name = loc1.name;
                    loc2.label = "";
                    loc2.width = buttonWidth;
                    loc2.height = buttonHeight;
                    if (loc1.styleName) 
                    {
                        loc2.styleName = loc1.styleName;
                    }
                    allButtons.push(loc2);
                    loc2.configEventListener(flash.events.MouseEvent.CLICK, btnClickHandler, false, 0, true);
                    this.addChild(loc2);
                }
                this.checkSelected();
                _dataProviderChange = false;
            }
            if (_selectedChange) 
            {
                _selectedChange = false;
                this.checkSelected();
            }
            super.updateDisplayList();
            return;
        }

        protected /* override */ checkSelected(): void
        {
            super.checkSelected();
            dispatchEvent(new MuiEvent(MuiEvent.GTABBAR_SELECTED_CHANGE, _selectedIndex));
            return;
        }

        public getSelectedButton(): Button
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < allButtons.length) 
            {
                loc1 = getChildAt(loc2) as Button;
                if (selectedIndex == loc2) 
                {
                    break;
                }
                ++loc2;
            }
            return loc1;
        }
    }
